home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / SDKs / Now Utilities Plug Ins 6.0 / API Stuff / Now Shortcuts Plug Ins ƒ / Move To Trash Plug In ƒ / Main.c next >
C/C++ Source or Header  |  1996-03-07  |  2KB  |  94 lines

  1. // Move To Trash Plug In
  2. //
  3. // © 1996 Now Software, Inc
  4. // written by: hac
  5.  
  6. #include "Main.h"
  7. #include "Power.h"
  8.  
  9. pascal void main(PlugInInformation *plugInInformation)
  10. {
  11.     plugInInformation->version = kPlugInInformationVersionOne;
  12.     plugInInformation->plugInType = kMoveToTrashPlugInType;
  13.     plugInInformation->PrepareMenu = &PrepareMenu;
  14.     plugInInformation->HandleMenuItemSelected = &HandleMenuItemSelected;
  15. }
  16.  
  17. pascal void PrepareMenu(InstantAccessInformation *information, short asPreview)
  18. {
  19.     OSErr                err;
  20.     MenuItemInformation    menuItem;
  21.  
  22.  
  23.     BlockMove("\pMove to Trash", menuItem.text, kMenuItemTextSize);
  24.             
  25.     menuItem.version = kMenuItemInformationVersionOne;
  26.     menuItem.classification = kMiscellaneousClassification;
  27.     menuItem.type = kTextMenuItemType;
  28.     menuItem.id = 1;
  29.     menuItem.enabled = true;
  30.     menuItem.style = 0;
  31.     menuItem.mark = 0;
  32.     menuItem.hasSubMenu = FALSE;
  33.     menuItem.subMenu = nil;
  34.     menuItem.refCon = 0;
  35.     menuItem.owningPlugInType = kMoveToTrashPlugInType;
  36.     
  37.     (*information->AddMenuItem)(&menuItem);
  38.  
  39. error:;
  40.  
  41. }
  42.  
  43. pascal void CleanUpAfterMenuSelect(InstantAccessInformation *information, short asPreview)
  44. {
  45.     //hmmmm....
  46. }
  47.  
  48. pascal void HandleMenuItemSelected(InstantAccessInformation *information, MenuItemInformation *menuItem)
  49. {
  50.     short                        selectedItemCount;
  51.     short                        index;
  52.     short                        foundVRefNum;
  53.     long                        foundDirID;
  54.     FSSpec                        fileSpec;
  55.     FSSpec                        trashSpec;
  56.     OSErr                        err;
  57.     Str255                        errStr;
  58.     void*                        itemReference;
  59.  
  60.     // Find the trash
  61.     err = FindFolder(kOnSystemDisk,kTrashFolderType,kDontCreateFolder,&foundVRefNum,&foundDirID);
  62.     if (err != noErr) {
  63.         goto error;
  64.     }
  65.  
  66.     // specify the root as a partial pathname
  67.     BlockMove(":", &errStr[1], 1);
  68.     errStr[0] = 1;
  69.     
  70.     // make an fsspec for it
  71.     err = FSMakeFSSpec(foundVRefNum, foundDirID, errStr, &trashSpec);
  72.     if (err != noErr) {
  73.         goto error;
  74.     }
  75.  
  76.     // Get the number of selected items
  77.     selectedItemCount = (*information->CountSelectedItems)();
  78.  
  79.     // Move each item to the trash
  80.     for (index = 0; index < selectedItemCount; index++) {
  81.         
  82.         itemReference = (*information->GetNthSelectedItemReference)(index);
  83.  
  84.         (*information->GetSelectedItemFileSpec)(itemReference, &fileSpec);
  85.  
  86.         err = FSpCatMove(&fileSpec,&trashSpec);
  87.         if (err != noErr) {
  88.             goto error;
  89.         }
  90.     }
  91.  
  92. error:;
  93. }
  94.